using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GameScene : MonoBehaviour
{
    // Start is called before the first frame update
    private int N = 64;
    public GameObject[] gameObjects;
    private PrimitiveType[] primTypes = new PrimitiveType[]{PrimitiveType.Cube, PrimitiveType.Capsule, PrimitiveType.Sphere};
    private Material[] materials;

    private void init()
    {
        
        materials = new Material[3];
        materials[0] = Resources.Load("mat1", typeof(Material)) as Material;
        materials[1] = Resources.Load("mat2", typeof(Material)) as Material;
        materials[2] = Resources.Load("mat3", typeof(Material)) as Material;

        gameObjects = new GameObject[N * N];

        for (int i = 0; i < N; i++)
        {
            for (int j = 0; j < N; j++)
            {
                gameObjects[i * N + j] = GameObject.CreatePrimitive(primTypes[UnityEngine.Random.Range(0, 3)]);
                gameObjects[i * N + j].transform.Translate((i - N/2) * 3, UnityEngine.Random.Range(-0.5f, 0.5f), (j - N/2) * 3);
                gameObjects[i * N + j].transform.Rotate(UnityEngine.Random.Range(0.0f, 180.0f),
                    UnityEngine.Random.Range(0.0f, 180.0f), UnityEngine.Random.Range(0.0f, 180.0f));
                gameObjects[i * N + j].GetComponent<Renderer>().material = materials[UnityEngine.Random.Range(0, 3)];
            }
        }
    }
    
    void Start()
    {
        init();
    }

    void OnDisable()
    {
        for(int i=0;i<gameObjects.Length;i++)
        {
            gameObjects[i] = null;
        }
        for(int i=0;i<materials.Length;i++)
        {
            materials[i] = null;
        }
    }

}
